home *** CD-ROM | disk | FTP | other *** search
- COMMENT - CKETEST.INI
- ;
- ; Exercises C-Kermit's programming constructs (see Ch.12, "Using C-Kermit").
- ;
- echo
- echo C-Kermit Programming-Constructs Test
- echo
- echo If you don't see the message "Proceeding..."
- echo on the next line, C-Kermit was not configured for script programming.
- check if
- echo Proceeding...
- echo
- if exist ckedemo.ini goto demo
- echo Can't find ckedemo.ini file, proceeding with other tests...
- goto other
-
- :DEMO
- take ckedemo.ini
- spellnum 0
- spellnum 1
- spellnum 2
- spellnum 3
- spellnum 4
-
- echo Calculator demo...
- calc
-
- echo Adding machine demo...
- addingmachine
-
- echo Recursive sum macro...
-
- def sum if not def \%1 return,- ; Make sure there is an argument
- if not numeric \%1 return,- ; Make sure argument is numeric
- if not > \%1 0 return,- ; Make sure argument is positive
- if = \%1 1 return 1,- ; If argument is 1, the sum is 1
- else return \feval(\%1 + \fexecute(sum \feval(\%1 - 1)))
-
- def addemup echo sum of 0..\%1 = \fexec(sum \%1)
- addemup 1
- addemup 2
- addemup 3
- addemup 4
- addemup 5
- addemup 10
- addemup 20
-
- :LOOP
- echo
- ask \%1 { Type 3 numbers separated by spaces: }
- if not def \%1 goto other
- smallest \%1
- goto loop
-
- :OTHER ; Other tests
-
- echo WHILE-LOOP TEST...
- echo You should see:
- echo { 0 1 2 3 4}
- def \%a 0
- while < \%a 5 { write scr { \%a}, incr \%a }
- echo
-
- echo NESTED WHILE-LOOP TEST...
- echo You should see:
- echo { 0:0 0:1 0:2 1:0 1:1 1:2 2:0 2:1 2:2}
- def \%a 0
- while < \%a 3 {-
- def \%b 0,-
- while < \%b 3 {-
- write scr { \%a:\%b},-
- incr \%b,-
- },-
- incr \%a -
- }
- echo
-
- echo FOR-LOOP INSIDE WHILE-LOOP
- echo You should see:
- echo { 1:1 1:2 1:3 2:1 2:2 2:3 3:1 3:2 3:3}
- def \%a 1
- while < \%a 4 { -
- for %i 1 3 1 { write scr { \%a:\%i} },-
- inc \%a -
- }
- echo
-
- echo WHILE-LOOP INSIDE FOR-LOOP
- echo You should see:
- echo { 1:1 1:2 1:3 2:1 2:2 2:3 3:1 3:2 3:3}
- for \%i 1 3 1 {-
- def \%a 1,-
- while < \%a 4 {-
- writ scr { \%i:\%a},-
- incr \%a -
- }-
- }
- echo
-
- echo NESTED FOR LOOP TEST
- echo You should see:
- echo { 1:1 1:2 1:3 2:2 2:3 3:3}
- for \%i 1 3 1 {-
- for \%j \%i 3 1 {-
- write scr { \%i:\%j} -
- }-
- }
- echo
-
- echo NESTED FOR/WHILE/BREAK/CONTINUE TEST
- echo You should see:
- echo { 1:1 1:3 3:1 3:3}
- for \%i 1 4 1 { -
- if = \%i 2 continue,-
- else if = \%i 4 break,-
- asg \%j 0,-
- while < \%j 4 { -
- incr \%j,-
- if = \%j 2 continue,-
- else if = \%j 4 break,-
- write screen { \%i:\%j} -
- },-
- }
- echo
- echo End of \v(cmdfile)
- echo
-